<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>商品展示列表</title>
    <link rel="stylesheet" href="styles.css">
</head>

<body>
    <div id="app">
        <!-- 路由出口，展示不同页面 -->
        <router-view></router-view>
    </div>

    <!-- 商品列表模板 -->
    <template id="product-list">
        <div>
            <h1>商品列表</h1>
            <div class="product-item" v-for="product in products" :key="product.id">
                <img :src="product.image" :alt="product.name">
                <h3>{{ product.name }}</h3>
                <p>{{ product.description }}</p>
                <button @click="goToDetailPage(product)">查看详情</button>
            </div>
        </div>
    </template>

    <!-- 商品详情模板 -->
    <template id="product-detail">
        <div>
            <h1>{{ product.name }}</h1>
            <img :src="product.image" :alt="product.name">
            <p>{{ product.description }}</p>
            <p>价格: {{ product.price }}</p>
            <p>评分: {{ product.rating }}</p>
            <button @click="$router.push('/')">返回列表</button>
        </div>
    </template>

    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue-router@3.5.3/dist/vue-router.js"></script>
    <script src="script.js"></script>
</body>

</html>